<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1、导入mapbox的依赖 -->
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <!-- 2、设置地图容器的挂载点 -->
    <div id="map">

    </div>
    <script>
        /* token */
        mapboxgl.accessToken = 'pk.eyJ1IjoiZXJpYzA5MTciLCJhIjoiY2x3cTI2Zzg0MWY2dDJqcWVpdDI1MHNpcCJ9.k9gLW7ZgLyISNdYHIEEGdQ'
        const map = new mapboxgl.Map({
            /* target-ol */
            container: 'map', // container ID
            /* style-layers */
            style: 'mapbox://styles/mapbox/streets-v12', // style URL
            center: [114.40088809833583,
                30.4663210497187], // starting position [lng, lat]
            zoom: 15, // starting zoom
            pitch: 70
        });
        /* 1、加载zhongdi的数据 */
        let data = 'http://39.103.151.139:8000/gis/zhongdi'
        map.on("style.load", () => {
            map.addSource("zhongdi-source", {
                type: "geojson",
                data
            })
            /* id,source,type */
            map.addLayer({
                id: "zhongdi-layer",
                source: "zhongdi-source",
                type: "fill-extrusion",
                paint: {
                    "fill-extrusion-color": "#652e80",
                    'fill-extrusion-height': 100,
                    "fill-extrusion-opacity": 0.6,
                    /* fill-extrusion-base可以设置建筑离地的高度 */
                    // "fill-extrusion-base": 150
                }
            })
            /* 禁止双击地图放大 */
            map.doubleClickZoom.disable()
        })
        /* 执行按下鼠标 */
        let timer = null;
        map.on("mousedown", () => {
            map.getCanvas().style.cursor = 'wait';
            timer = setInterval(() => {
                /* 获取高度 */
                let height = map.getPaintProperty("zhongdi-layer", "fill-extrusion-height")
                // console.log(height)
                height += 5;
                /* 设置高度 */
                map.setPaintProperty("zhongdi-layer", "fill-extrusion-height", height)
            }, 20)

        })
        /* 执行松开鼠标 */
        map.on("mouseup", () => {
            console.log("up")
            map.getCanvas().style.cursor = "default"
            clearInterval(timer)
        })
    </script>
</body>

</html>